from multiprocessing import *
import time
import os


# 子进程1
def worker_1(t):
    print("child process1:", os.name, os.getpid())
    time.sleep(t)
    print("end worker_1")


# 子进程2
def worker_2(t):
    print("child process2:", os.name, os.getpid())
    time.sleep(t)
    print("end worker_2")


# 子进程3
def worker_3(t):
    print("child process3:", os.name, os.getpid())
    time.sleep(t)
    print("end worker_3")


if __name__ == "__main__":
    p1 = Process(target=worker_1, args=(4,))
    p2 = Process(target=worker_2, args=(3,))
    p3 = Process(target=worker_3, args=(2,))

    start = time.time()
    p1.start()  # 启动子进程1
    p2.start()  # 启动子进程2
    p3.start()  # 启动子进程3
    p1.join()
    p2.join()
    p3.join()
    # 总消耗时间大致为子进程消耗时间最长的时间：4s
    end = time.time() - start
    print("消耗的时间为：", end)